<?php
// 本类由系统自动生成，仅供测试用途
class ZhucaoAction extends Action {

	
	

    //公版
    public function query(){
    	header("Content-Type:text/html; charset=utf-8");
    	$environment=D('Environment');$plan=D('Plan');$ps=D('Ps');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];

      $lineid=$usross['f_usr_lineid'];
      
      $arr_planls=$plan->getplanlsbylineid($lineid);$planls=$arr_planls['data'];

      $planlsnw=array();
      foreach($planls as $planv){
        // $arr_data=$ps->getsumvolumebyplanid($planv['planid']);$data=$arr_data['data'];
        // $planv['data']=$data;
        //需求有改变//需要研究哪个部件百分比最低，运输的最慢，因此产生的件-》箱最少
        $arr_psls=$ps->getpslsbyplanid($planv['planid']);$psls=$arr_psls['data'];
        $psrate_ref=0;$pso_ref=array();
        $i=0;
        foreach($psls as $psv){
          $psrate=$psv['psalready']/$psv['psvolume'];
          if($i==0){$psrate_ref=$psrate;$pso_ref=$psv;}
          if($psrate<$psrate_ref){
            $psrate_ref=$psrate;
            $pso_ref=$psv;
          }
          $i++;
        }
        //计算箱数
        $xiang=$pso_ref['psalready']/$pso_ref['partvolumepc'];
        $planv['xiang']=$xiang;
        
        array_push($planlsnw,$planv);
      }
      $this->assign('planls',$planlsnw);



      $tm=date('Y.m.d',time());
      $this->assign('tm',$tm);
      
      $this->assign('ttl','主操');
      $this->display('query');
  
    }

    public function doqueding(){
      header("Content-Type:text/html; charset=utf-8");
      $plan=D('Plan');$ps=D('Ps');

      $planid=gp()['planid'];

      
      $plan->changeplanodr($planid);

      $ps->changestatbyqueding($planid);

      
      $this->ajaxReturn($data,'json');
      
    }
    
    public function dojiapei(){
      header("Content-Type:text/html; charset=utf-8");
      $plan=D('Plan');$ps=D('Ps');

      $planid=gp()['planid'];
      $jiapeishuliang=gp()['jiapeishuliang'];

      //第一步计划表要改
      $plan->jiapei($planid,$jiapeishuliang);
      //第二步ps配送要改
      $ps->jiapei($planid,$jiapeishuliang);

      
      $this->ajaxReturn($data,'json');
      
    }


    public function dowancheng(){
      header("Content-Type:text/html; charset=utf-8");
      $plan=D('Plan');$ps=D('Ps');

      $planid=gp()['planid'];

      $plan->wancheng($planid);

      $ps->wancheng($planid);
      
      $this->ajaxReturn($data,'json');
      
    }
    
    public function showsqlresult(){
      header("Content-Type:text/html; charset=utf-8");

      $sql=D('Sql');

      $environment=D('Environment');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];

      $sqltxt=gp()['sqltxt'];

      $arr_result=$sql->exesql($sqltxt);$result=$arr_result['data'];
      
      $this->assign('result',$result);
      $this->assign('ttl','结果');
      $this->display('showsqlresult');
  
    }

    public function showsqlresult_table(){
      header("Content-Type:text/html; charset=utf-8");
      $sql=D('Sql');

      $environment=D('Environment');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];

      $sqltxt=gp()['sqltxt'];

      $arr_result=$sql->exesql($sqltxt);$result=$arr_result['data'];
      
      $this->assign('result',$result);
      $this->assign('ttl','结果_表格');
      $this->display('showsqlresult_table');
  
    }

}